package com.rr.easy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhuangcanrun
 * @Date 2022/01/19/12:19
 * @description
 **/
/*
 * https://leetcode-cn.com/problems/contains-duplicate-ii/
 * */
public class ContainsNearbyDuplicate {
    public boolean containsNearbyDuplicate(int[] nums, int k) {
        Map<Integer, Integer> map = new HashMap<>();
        int length = nums.length;
        for (int i = 0; i < length; i++) {
            if (map.containsKey(nums[i])) {
                Integer integer = map.get(nums[i]);
                if (i - integer <= k) {
                    return true;
                }
            }
            map.put(nums[i], i);
        }
        return false;
    }

    public static void main(String[] args) {
        final HashMap<Integer, Integer> map = new HashMap<>(4);
        map.put(1, 1);
        map.put(2, 1);
        map.put(3, 1);
        map.put(4, 1);
        map.put(5, 1);
        map.put(6, 1);
        map.put(7, 1);
        System.out.println(map.size());
    }
}
